function minCost(colors, neededTime) {
  let totalTime = 0;
  let i = 0;
  const n = colors.length;

  while (i < n) {
    const currentColor = colors[i];
    let sum = 0;
    let maxTime = 0;

    // 处理连续相同颜色的气球
    while (i < n && colors[i] === currentColor) {
      sum += neededTime[i];
      maxTime = Math.max(maxTime, neededTime[i]);
      i++;
    }

    // 累加移除当前连续段中除最大时间气球外的总时间
    totalTime += sum - maxTime;
  }

  return totalTime;
}
